package me.magicall.web.simple.spring.controllers;

import java.util.HashMap;
import java.util.Map;

import me.magicall.tagInterfaces.Reloadable;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller("cacheController")
@RequestMapping("/admin/cache")
public class CacheController implements ApplicationContextAware {

	private final Map<String, Reloadable> reloadableBeans = new HashMap<String, Reloadable>();

	@Override
	public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
		final String[] names = applicationContext.getBeanDefinitionNames();
		for (final String name : names) {
			final Object o = applicationContext.getBean(name);
			if (o instanceof Reloadable) {
				reloadableBeans.put(name, (Reloadable) o);
			}
		}
		System.out.println("@@@@@@CacheController.setApplicationContext():" + reloadableBeans);
	}

}
